#!/usr/bin/env bash
base_path=~/docker/ELK/elasticsearch
port1=9200
port2=9300
container_name=elk-elasticsearch
script_pwd=$(dirname "$0")

rm -rf $base_path/config 
mkdir -p $base_path/logs
mkdir -p $base_path/data
mkdir -p $base_path/plugins
cp -r $script_pwd/config $base_path/.

docker rm -f $container_name

docker run -d \
  --ulimit memlock=-1:-1 \
  -p $port1:9200 \
  -p $port2:9300 \
  -e "ELASTIC_PASSWORD=changeme" \
  -e TZ=Asia/Shanghai \
  -v $base_path/config:/usr/share/elasticsearch/config \
  -v $base_path/data:/usr/share/elasticsearch/data \
  -v $base_path/logs:/usr/share/elasticsearch/logs \
  -v $base_path/plugins:/usr/share/elasticsearch/plugins \
  --name $container_name \
  docker.elastic.co/elasticsearch/elasticsearch:8.16.1

# docker exec -it elk-elasticsearch /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -i
# docker exec -it elk-elasticsearch /usr/share/elasticsearch/bin/elasticsearch-reset-password -u kibana_system -i
